//
//  OMFakeCategoryData.m
//  OMENGO
//
//  Created by 梁尚嘉 on 2017/4/18.
//  Copyright © 2017年 Kamfat. All rights reserved.
//

#import "OMFakeCategoryData.h"
#import <UIKit/UIKit.h>
#import "BaseViewController.h"
@implementation OMFakeAction

+ (void)asyncLoadLocalImage:(NSString *)imgStr
                inImageView:(UIImageView *)imageView
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        UIImage *image = [UIImage imageNamed:imgStr];
        dispatch_async(dispatch_get_main_queue(), ^{
            [imageView setImage:image];
        });
    });
}

+ (void)fakeLoadDataActionWithController:(BaseViewController *)controller
{
    [controller startAnimating:true];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [controller startAnimating:NO];
    });
}

+ (void)cartAnimationAddWithButton:(UIButton *)button toTargetView:(UIView *)targetView
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        KTSystemStorageSingleton.numOfCartItem++;
    });

    if (!targetView) {
        targetView = KTSystemStorageSingleton.badgeView;
    }

//    //若隐藏则取消动画
//    if (targetView.hidden) {
//        return;
//    }

    if (!button || !targetView) {
        [OMHUD HUDSuccess:@"成功加入购物车"];
        return;
    }

    CGPoint generatePoint = [button.superview convertPoint:button.center toView:[Navigator currentNavigationController].topViewController.view];
    CGPoint middlePoint = CGPointMake(generatePoint.x-SM_SIZE(200), generatePoint.y-SM_SIZE(200));
    CGPoint distinatePoint = [targetView.superview convertPoint:targetView.center toView:[Navigator currentNavigationController].topViewController.view];;

    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:generatePoint];
    [path addQuadCurveToPoint:distinatePoint controlPoint:middlePoint];

    CAShapeLayer *dot   = [CAShapeLayer layer];
    CGFloat width       = SM_SIZE(30);
    dot.frame           = CGRectMake(0, 0, width, width);
    dot.position        = distinatePoint;
    dot.backgroundColor = SM_dotRedColor.CGColor;
    dot.cornerRadius    = width/2;
    dot.masksToBounds   = YES;
    [[Navigator currentNavigationController].topViewController.view.layer addSublayer:dot];

    double duration                 = .5f;
    CAKeyframeAnimation *animation  = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.path                  = path.CGPath;
    animation.duration              = duration;
    animation.timingFunction        = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    [dot addAnimation:animation forKey:nil];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [dot removeFromSuperlayer];
        [targetView addInstanceScaleAnimationWithTargetScale:1.1
                                                     reverse:YES
                                                    duration:.1];
    });
}

@end

@implementation OMFakeCategoryData


+ (NSArray *)fakeData
{
    return  [OMFakeCategoryData mj_objectArrayWithKeyValuesArray:
             @[
               @{@"name":@"热门推荐",@"id":@"123434",},
               @{@"name":@"牛奶乳品",@"id":@"123434",},
               @{@"name":@"饮料酒水",@"id":@"123434",},
               @{@"name":@"休闲零食",@"id":@"123434",},
               @{@"name":@"方便速食",@"id":@"123434",},
               @{@"name":@"冲调茶饮",@"id":@"123434",},
               @{@"name":@"生活用品",@"id":@"123434",},
               @{@"name":@"粮油调料",@"id":@"123434",},
               @{@"name":@"雪糕冰品",@"id":@"123434",},
               @{@"name":@"进口食品",@"id":@"123434",},
               @{@"name":@"熟食简餐",@"id":@"123434",},
               ]];
}
@end

@implementation OMFakeGoodData
+ (NSArray *)fakeData
{
    return [OMFakeGoodData mj_objectArrayWithKeyValuesArray:
            @[
              @{@"image":@"可拉奥怪薯薯非油炸",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"乐事大波浪薯片烤鸡味桶装.jpg",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"旺仔牛奶大罐",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"VFOODS香辣味",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"小茗同学溜溜哒",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"小茗同学绿茶味",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"康师傅乌龙名茶",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"旺仔牛奶大罐",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"白沙（蓝尚品）",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"和其正小瓶",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"乐事大波浪薯片烤鸡味桶装.jpg",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"加多宝罐装",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"乐事大波浪薯片鱿鱼.jpg",@"spec":@"60g/袋",@"price":@"9.9"},
              @{@"image":@"乐事大波浪薯片烤鸡味.jpg",@"spec":@"60g/袋",@"price":@"9.9"},
              ]];
}
@end
